﻿using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DreamCube.Foundation.Basic.Utility;

namespace DreamCube.Websites.LogWeb
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CreateSystemList();
        }

        protected void CreateSystemList()
        {
            try
            {
                String configFileFullName = MyWebsite.MapPath(Path.Combine(MyPage.CurFolderPath, "Configs.xml"));
                XmlDocument doc = new XmlDocument();
                doc.Load(configFileFullName);

                XmlNodeList pathsNodeList = doc.SelectNodes("LogPaths/LogPath");
                if (pathsNodeList != null && pathsNodeList.Count > 0)
                {
                    StringBuilder builder = new StringBuilder();
                    String template = "<br>{0}、&nbsp;<a href='{1}'>{2}</a><br>";
                    String url = MyPage.CurFolderUrl + "Pages/ViewLog.aspx?logPath={0}&title={1}";
                    for (Int32 i = 0; i < pathsNodeList.Count; i++)
                    {
                        String name;
                        String path;
                        MyXml.TryGetNodeAttributeValue(pathsNodeList[i], "Name", out name, false, MyXml.XmlValueType.InnerText);
                        MyXml.TryGetNodeAttributeValue(pathsNodeList[i], "Path", out path, false, MyXml.XmlValueType.InnerText);
                        builder.AppendFormat(template, i + 1, String.Format(url, HttpUtility.UrlEncode(path), HttpUtility.UrlEncode(name)), name);
                    }
                    lt_SystemList.Text = builder.ToString();
                }
            }
            catch (Exception ex)
            {
                MyLog.MakeLog(ex);
            }
        }
    }
}